// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
// import fastClick from 'fastclick'
import store from './store'
import Axios from 'axios'
import 'babel-polyfill'
import 'styles/reset.css'
import 'styles/common.styl'
import 'styles/iconfont/iconfont.css'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'

// Axios.defaults.baseURL = '/api'
Axios.defaults.baseURL = 'http://www.duxue365.cn:8081'
Axios.defaults.headers.post['Content-Type'] = 'application/json'
Axios.defaults.timeout = 10000
Axios.interceptors.response.use(function (response) {
// 对响应数据做点什么
  return response
}, function (err) {
  if (err && err.response) {
    switch (err.response.status) {
      case 400:
        err.message = '请求错误(400)'
        break
      case 401:
        err.message = '未授权，请重新登录(401)'
        break
      case 403:
        err.message = '拒绝访问(403)'
        break
      case 404:
        err.message = '请求出错(404)'
        break
      case 408:
        err.message = '请求超时(408)'
        break
      case 500:
        err.message = '服务器错误(500)'
        break
      case 501:
        err.message = '服务未实现(501)'
        break
      case 502:
        err.message = '网络错误(502)'
        break
      case 503:
        err.message = '服务不可用(503)'
        break
      case 504:
        err.message = '网络超时(504)'
        break
      case 505:
        err.message = 'HTTP版本不受支持(505)'
        break
      default:
        err.message = `连接出错(${err.response.status})!`
    }
  } else {
    err = '网络链接失败'
    // console.log(err)
    // err.message = '连接服务器失败!'
  }
  // message.error(err.message)
  return Promise.reject(err)
})

Vue.prototype.$axios = Axios

Vue.config.devtools = true
Vue.config.productionTip = false
// fastClick.attach(document.body)
Vue.use(VueAwesomeSwiper/* { default global options } */)

// 设置title
router.beforeEach((to, from, next) => {
  window.document.title = to.meta.title
  next()
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {App},
  template: '<App/>'
})
